package comcksys.authserver.service.impl;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 自定义Security用户信息
 * @author: yxzhang23
 * @time: 2021/4/9
 */
@Data
public class MyUserDetailsImpl implements UserDetails {

    private static final long serialVersionUID = 8081363717997957932L;

    private String username;
    private String password;
    private List<SimpleGrantedAuthority> authorities;
    private Boolean expired = false;
    private Boolean locked = false;
    private Boolean credentialExpired = false;
    private Boolean enabled = true;

    public MyUserDetailsImpl(String username, String password, List<SimpleGrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return !this.expired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !this.locked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return !this.credentialExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}
